package com.sc.VenusQueryBeta.ui.activites;

import android.os.Bundle;
import android.os.Handler;
import android.support.design.widget.AppBarLayout;
import android.support.v7.widget.RecyclerView;
import android.support.v7.widget.Toolbar;
import android.view.View;
import android.widget.TextView;

import com.hengjun.kingstar.sdk.base.activity.BaseCompatActivity;
import com.sc.VenusQueryBeta.R;


import butterknife.BindView;
import in.srain.cube.views.ptr.PtrClassicFrameLayout;
import in.srain.cube.views.ptr.PtrDefaultHandler;
import in.srain.cube.views.ptr.PtrFrameLayout;
import in.srain.cube.views.ptr.header.MaterialHeader;

/**
 * 消息列表页面
 */
public class MsgActivity extends BaseCompatActivity {

    public static boolean isForeground = false;
    public static final String MESSAGE_RECEIVED_ACTION = "com.example.jpushdemo.MESSAGE_RECEIVED_ACTION";
    public static final String KEY_MESSAGE = "message";
    public static final String KEY_EXTRAS = "extras";

    @BindView(R.id.setting_name)
    TextView settingName;
    @BindView(R.id.toolbar)
    Toolbar toolbar;
    @BindView(R.id.setting_title)
    AppBarLayout settingTitle;
    @BindView(R.id.rv_vip_list)
    RecyclerView rvVipList;
    @BindView(R.id.ptr_class)
    PtrClassicFrameLayout ptrClass;

    @Override
    protected void initView(Bundle savedInstanceState) {
        toolbar.setNavigationOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                finish();
            }
        });
    }

    @Override
    protected void initData() {
        super.initData();
        reFreshListener();
    }

    /**
     * 下拉刷新監聽
     */
    private void reFreshListener() {
        MaterialHeader header = new MaterialHeader(this);
        ptrClass.addPtrUIHandler(header);
        ptrClass.setLastUpdateTimeRelateObject(this);//设置刷新支持时间
        ptrClass.setResistance(1.7f);//设置下拉的阻尼系数，值越大感觉越难下拉
        ptrClass.setDurationToCloseHeader(1000);//设置刷新完成，头部回弹时间，注意和前一个进行区别
        ptrClass.setPullToRefresh(false);//设置下拉过程中执行刷新，我们一般设置为false
        ptrClass.setKeepHeaderWhenRefresh(true);//设置刷新的时候是否保持头部
        ptrClass.postDelayed(new Runnable() {//进入Activity就进行自动下拉刷新
            @Override
            public void run() {
                ptrClass.autoRefresh();
            }
        }, 100);
        ptrClass.setPtrHandler(new PtrDefaultHandler() {               //下拉刷新
            @Override
            public void onRefreshBegin(PtrFrameLayout frame) {
                //模拟联网，延迟更新数据
                new Handler().postDelayed(new Runnable() {
                    @Override
                    public void run() {
//                                             mAdapterWithHF.notifyDataSetChanged();//适配器更新数据
                        ptrClass.refreshComplete();//
                    }
                }, 1000);
            }
        });
    }

    @Override
    protected int getLayoutId() {
        return R.layout.activity_msg;
    }

}
